package com.fanh.controller;

import com.fanh.common.api.CommonPage;
import com.fanh.common.api.CommonResult;
import com.fanh.dto.GuideCourseParam;
import com.fanh.dto.GuideCourseResult;
import com.fanh.model.GuideCourse;
import com.fanh.model.GuideCourseCategory;
import com.fanh.model.GuideCourseColumn;
import com.fanh.model.GuideCourseExample;
import com.fanh.service.GuideCourseCategoryService;
import com.fanh.service.GuideCourseColumnService;
import com.fanh.service.GuideCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@Api(tags = "HomeManagerController", description = "首页管理")
@RequestMapping("/a/guide/s")
public class HomeManagerController {


    @Autowired
    private GuideCourseCategoryService guideCourseCategoryService;
    @Autowired
    private GuideCourseService guideCourseService;
    @Autowired
    private GuideCourseColumnService guideCourseColumnService;

    @ApiOperation("搜索接口")
    @RequestMapping(value = "/course/autocomplete", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult autocomplete(@ApiParam(value = "名称", required = false)@RequestParam(name = "name") String name) {
        int pageNo=1;
        int PageSize=5;
        List list =guideCourseService.findListNames(name,null,pageNo,PageSize);
        return CommonResult.success(list);
    }

    @ApiOperation("热门搜索")
    @RequestMapping(value = "/course/hotsearch", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult hotsearch() {
        int pageNo=1;
        int PageSize=5;
        String publish= "1";
        List list =guideCourseService.findListNames(null,publish,pageNo,PageSize);
        return CommonResult.success(list);
    }

    @ApiOperation("广告栏")
    @RequestMapping(value = "/course/top", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult top() {
        GuideCourseParam course =new GuideCourseParam();
        course.setPublish("1");
        course.setPublish("1");
        List<GuideCourseResult>  list = guideCourseService.findList(course);
        return  CommonResult.success(list);
    }

    @ApiOperation("搜索接口")
    @RequestMapping(value = "/course/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult list(@RequestParam(required = false, defaultValue = "1") Integer pageNo,
                     @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                               GuideCourseParam course) {

         course.setPublish("1");
        if("2".equals(course.getType())) { //课程
            course.setHighlight("1"); // 精品
        }
        List<GuideCourseResult>  list = guideCourseService.findList(course, pageNo,pageSize);
        return  CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation("顶部类型")
    @RequestMapping(value = "/course/categories", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult categories() {
        List<GuideCourseCategory> categorys = guideCourseCategoryService.findList();
        return CommonResult.success(categorys);
    }

    @ApiOperation("查询全部的课程自定义属性")
    @RequestMapping(value = "/course/selectColumnList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult selectColumnList(  Map<String, Object> params) {
        List<GuideCourseColumn> list = guideCourseColumnService.selectColumnList(params);
        return CommonResult.success(list);
    }

    @ApiOperation("根据自定义属性id 查询课程")
    @RequestMapping(value = "/course/listForColumn", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult listForColumn(@ApiParam(value = "id", required = false)@RequestParam("id") Integer id) {
        GuideCourseParam course =new GuideCourseParam();
        course.setColumnId(id);
        List<GuideCourseResult>  list = guideCourseService.findList(course);
        return CommonResult.success(list);
    }

}
